﻿namespace Sidvall.LogManager.Net.Services.V1
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class LogScope : global::Sidvall.Data.ServiceDataRowBase, global::Sidvall.LogManager.Data.ILogScope
    {
        #region Public Members

        #region LogScopeId

        private System.Nullable<long> _LogScopeId;
        partial void OnBeforeLogScopeIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData);
        partial void OnAfterLogScopeIdPropertyChanged();
        public System.Nullable<long> LogScopeId
        { 
            get
            {
                return _LogScopeId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _LogScopeId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<long>>(value, _LogScopeId);
                    OnBeforeLogScopeIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("LogScopeId", eventData.Value, true, true);
                        OnAfterLogScopeIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region Name

        private string _Name;
        partial void OnBeforeNamePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterNamePropertyChanged();
        public string Name
        { 
            get
            {
                return _Name;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _Name = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Name);
                    OnBeforeNamePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("Name", eventData.Value, true, true);
                        OnAfterNamePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region ServerConnectionId

        private System.Nullable<System.Int32> _ServerConnectionId;
        partial void OnBeforeServerConnectionIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<System.Int32>> eventData);
        partial void OnAfterServerConnectionIdPropertyChanged();
        public System.Nullable<System.Int32> ServerConnectionId
        { 
            get
            {
                return _ServerConnectionId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _ServerConnectionId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<System.Int32>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<System.Int32>>(value, _ServerConnectionId);
                    OnBeforeServerConnectionIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("ServerConnectionId", eventData.Value, true, true);
                        OnAfterServerConnectionIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowStateIsDirty

        protected override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeManager.DataRowStateIsDirty(this);
            }
        }

        #endregion
        
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public LogScopeItemCollectionItem LogScopeItems { get; set; }
        #region LoadLogScopeItems

        public void LoadLogScopeItems(LogScopeItemCollectionItem value)
        {
            LoadInstanceField("LogScopeItems", value, true, false);
        }

        #endregion
        #region LoadLogScopeItemsAsync

        public async System.Threading.Tasks.Task<LogScopeItemCollectionItem> LoadLogScopeItemsAsync()
        {
            return await LoadLogScopeItemsAsync(false, true, null, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<LogScopeItemCollectionItem> LoadLogScopeItemsAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchListCriteria<global::Sidvall.LogManager.Data.Fields.LogScopeItemField, global::Sidvall.LogManager.Data.Relations.LogScopeItemRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.LogManager.SystemContext.Current.DataPortal.LogScopeManager.LoadLogScopeItemsAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters).ConfigureAwait(false);

            return this.LogScopeItems;
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool updateState)
        {
            global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeManager.LoadInstanceField(this, fieldName, value, cascade, false, updateState);
        }

        #endregion
        #region Copy

        public LogScope Copy()
        {
            return global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeManager.Copy(this);
        }
        public LogScope Copy(Sidvall.Data.CopySettings settings)
        {
            return global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeManager.Copy(this, settings);
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.LogManager.Data.ILogScope item)
        {
            global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeManager.Import(this, item);
        }
        public void Import(global::Sidvall.LogManager.Data.ILogScope item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeManager.Import(this, item, settings);
        }

        #endregion
        #region SaveItemAsync

        public async System.Threading.Tasks.Task<LogScope> SaveItemAsync()
        {
            return await global::Sidvall.LogManager.SystemContext.Current.DataPortal.LogScopeManager.SaveItemAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<LogScope> SaveItemAsync(Sidvall.Data.SaveMode mode)
        {
            return await global::Sidvall.LogManager.SystemContext.Current.DataPortal.LogScopeManager.SaveItemAsync(this, mode).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<LogScope> SaveItemAsync(Sidvall.Data.SaveSettings settings)
        {
            return await global::Sidvall.LogManager.SystemContext.Current.DataPortal.LogScopeManager.SaveItemAsync(this, settings).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<LogScope> SaveItemAsync(Sidvall.Data.SaveSettings settings, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            return await global::Sidvall.LogManager.SystemContext.Current.DataPortal.LogScopeManager.SaveItemAsync(this, settings, strategyContext, objectParameters).ConfigureAwait(false);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeManager.ValidateAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            return await global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeManager.ValidateAsync(this, settings).ConfigureAwait(false);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeManager.Initialize(this, settings);
        }

        #endregion

        #region ILogScope Members

        System.Nullable<long> global::Sidvall.LogManager.Data.ILogScope.LogScopeId
        {
            get
            {
                return this._LogScopeId;
            }
            set
            {
                this._LogScopeId = value;
            }
        }
        string global::Sidvall.LogManager.Data.ILogScope.Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                this._Name = value;
            }
        }
        System.Nullable<System.Int32> global::Sidvall.LogManager.Data.ILogScope.ServerConnectionId
        {
            get
            {
                return this._ServerConnectionId;
            }
            set
            {
                this._ServerConnectionId = value;
            }
        }
        System.Collections.Generic.IEnumerable<global::Sidvall.LogManager.Data.ILogScopeItem> global::Sidvall.LogManager.Data.ILogScope.LogScopeItems
        {
            get
            {
                if (this.LogScopeItems != null)
                    return this.LogScopeItems.Items;
                return null;
            }
        }
        void global::Sidvall.LogManager.Data.ILogScope.SetLogScopeItems(Sidvall.Data.IDataRowProvider<global::Sidvall.LogManager.Data.ILogScopeItem> items)
        {
            this.LogScopeItems = (LogScopeItemCollectionItem)items;
        }

        #endregion

        #endregion
        #region Constructors

        public LogScope()
        {
        }
        public LogScope(bool initializeDefaultValues)
            : this(initializeDefaultValues, null, Sidvall.Business.BusinessEvents.None)
        {
        }
        public LogScope(bool initializeDefaultValues, Sidvall.Data.DataRowState? dataRowState, Sidvall.Business.BusinessEvents enabledBusinessEvents)
            : base(dataRowState, enabledBusinessEvents)
        {
            if (initializeDefaultValues)
                global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeManager.Initialize(this);
        }

        #endregion
    }
}